package com.example.werthwedemo0309;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;

import com.example.werthwedemo0309.IntentData.IWeatherPresenter;
import com.example.werthwedemo0309.fragment.Aadapter;
import com.example.werthwedemo0309.fragment.Amodel;
import com.example.werthwedemo0309.fragment.ContactModel;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class twoActivity extends AppCompatActivity {
    private static final String TAG = twoActivity.class.getSimpleName();
    private  RecyclerView recyclerView;
    private WeatherPresenter weatherLogic;
    private Aadapter aadapter=new Aadapter(this);
    private Set<String> cityHash = new HashSet<String>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        List<Amodel> data=new ArrayList<>();
        recyclerView=findViewById(R.id.recle);
        LinearLayoutManager llm = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(llm);
        weatherLogic = new WeatherPresenter();

        weatherLogic.requestCityList("b399f1b894aa3ee7154dbf1ed2b75ba7",
                new IWeatherPresenter()
                {
                    @Override
                    public void onCityListSuccess(List<CityModel> cityList)
                    {
                        for (int i = 0; i < cityList.size(); i++)
                        {
                            Log.d(TAG,"数据"+cityList.get(i).getCity());
                            Log.d("城市列表去重前", cityList.get(i).getCity());
                            cityHash.add(cityList.get(i).getCity());
                        }
                        for (String i : cityHash) {
                            Log.d("城市列表去重后", i);
                            Amodel list = new Amodel();
                            list.setCity(i);
                            data.add(list);
                            aadapter.setData(data);
                            recyclerView.setAdapter(aadapter);
                    }
                }
                });
    }
    }


